put " click the mouse to exit demo" after field "data"
wait until the mouseclick
hide field "data"
end mouseUp
-- part contents for background part 68
----- text -----
DisAsm is the principal XFCN included in this stack. It returns the 68000 instruction stored at a given address. It has a few other useful options as well. In its simplest form, DisAsm can be used to just look at the instruction stored at a given location. For example, if you write
put DisAsm("411000") into field "Data"
then (on a Mac Plus) the field data will get the value:
MOVEM.L (A7)+, D0/D1/D2
(Go ahead and try DisAsm("411000") from the message box)
However, you will generally want to use DisAsm to look at the assembly language instructions stored in several consecutive locations. So that it will be straightforward to write a script to disassemble a linear range of addresses, DisAsm contains several options.
First, you can add a second parameter (an L is used here, but any second parameter would serve as well). If DisAsm sees a second parameter, then it will return the 8 instructions stored starting at the given address. It returns these instructions in the following format
instruction (return)
next address instruction (return)
next address instruction (return)
next address instruction (return)
next address instruction (return)
next address instruction (return)
next address instruction (return)
next address instruction (return)
next address
This makes it fairly simple to write a script that will quickly disassemble a long range of addresses.
See the demo provided on this card as an example. Also see the script of the card "disassembler" for a more elaborate (and typical) useage of the DisAsm XFCN.
If a third parameter is included with the DisAsm XFCN
e.g. DisAsm(Address,L,L)
then the result returned consists of eight lines (as above) but some extra formatting gets thrown in too. For instance a carriage return is appended after any instruction of the form BRA, RTS, or JMP. This makes it easier to see exactly where the code segment breaks into "pieces".
As with the other XFCN's in this stack, the address provided to DisAsm can either be included in quotes or may begin with an H to signify that it is a hexadecimal value. I suggest that you generally use the option of preceeding addresses with an H to avoid complaints from Hypercard.
DisAsm expects to get an even address, but if you supply an odd address, then DisAsm will simply add one to make it even. If the address is not a legal hexstring, then DisAsm returns an empty string.
Comments on What You Will See
Note that an instruction such as MOVE.L D2,-(A7) is changed to PUSH.L D2 - which is more nmemonic and represents a standard maco on many assemblers. Recall that A7 is used as the stack pointer.
Similarly, MOVE.W (A7)+,D3 will appear as POP.W D3.
Also, ALL numerical values returned by DisAsm are hexadecimal. You can use the HexToDec XFCN to convert some of these to decimal values if you like.
Note that DisAsm converts all trapwords to their symbolic name as given in Inside Macintosh.
If you can't think of anything to disassemble, try looking at some traps. Go to the disassembler card, choose the traps option and ask for MenuSelect (or whatever trap you like).